package com.itheima.demo;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

/**
 * @author Zhang_Han
 * @version 1.0
 * @date 2020/7/19 19:04
 */
public class Demo_Calendar {
    public static void main(String[] args) {
        //创建日期类对象;
        Calendar calendar = Calendar.getInstance();
        //get(int field)【记】:获取某个字段的值;
        Date time = calendar.getTime();
        System.out.println(time);
        System.out.println("-----------------------");
        //set(int field,int value):【记】修改某一个字段的值;
        calendar.set(Calendar.YEAR,2021);
        Date time1 = calendar.getTime();
        System.out.println(time1);
        System.out.println("-----------------------");
        //add(int field,int value):【记】在某个原有字段上的值进行加减;
        calendar.add(Calendar.YEAR,1);
        int i = calendar.get(Calendar.YEAR);
        System.out.println(i);
        //setTime(Date date):将date的值赋值给Calander;
        Date date = new Date();
        calendar.setTime(date);
        Date time2 = calendar.getTime();
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH-mm-ss");
        String s = sdf.format(time2);
        System.out.println(s);

    }
}
